
package com.lmx.repoDomain.repository;

import javax.annotation.PostConstruct;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.common.context.ActionContextHolder;
import com.lmx.persistence.service.PayRecordService;
import com.lmx.repoDomain.tmodel.Wechat;

import io.katharsis.repository.annotations.JsonApiResourceRepository;
import io.katharsis.repository.annotations.JsonApiSave;

@JsonApiResourceRepository(Wechat.class)
@Component
public class WechatRepository extends BaseRepository<Wechat>{
    @Autowired
    private PayRecordService payRecordService;

    @PostConstruct
    public void init() {
        dslJpaService.setEntityClass(Wechat.class);
    }

    @Override
    @JsonApiSave
    public Wechat save(Wechat wechat) {
        String action = ActionContextHolder.getContext().getAction();
        if(StringUtils.isNotBlank(action) && "wechatBind".equals(action)){
            wechat = payRecordService.bindQr(wechat);
        }
    /*    if (wechat.getId() == null){

        }else {
            dslJpaService.update(wechat);
        }*/
        return wechat;
    }

}
